﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UM_SERVER.Packet.InPacket
{
    class ModifyProdPacket : BaseInPackage
    {
        public ModifyProdPacket(InPackage inpackage) : base(inpackage)
        {

        }

        public override void InitPackage()
        {
            int Offset = 0;
            //用户名长度
            byte[] UsernameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, UsernameLength, 0, 4);
            Offset += 4;
            //读取用户名
            byte[] Username = new byte[BitConverter.ToInt32(UsernameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Username, 0, Username.Length);
            Offset += Username.Length;
            //得到个性签名长度
            byte[] ProdLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, ProdLength, 0, 4);
            Offset += 4;
            //得到个性签名
            byte[] Prod = new byte[BitConverter.ToInt32(ProdLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Prod, 0, Prod.Length);
            Offset += Prod.Length + 2;
            //IP地址长度
            byte[] IPLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, IPLength, 0, 4);
            Offset += 4;
            //IP地址
            byte[] IPAddress = new byte[BitConverter.ToInt32(IPLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, IPAddress, 0, IPAddress.Length);
            Offset += IPAddress.Length;
            //聊天端口
            byte[] Talkport = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Talkport, 0, 4);

            this.DIC_CONTENT.Add("USERNAME", Username);
            this.DIC_CONTENT.Add("PROD", Prod);
            this.DIC_CONTENT.Add("IPADDRESS", IPAddress);
            this.DIC_CONTENT.Add("TALKPORT", Talkport);
        }

        /// <summary>
        ///     得到用户新个性签名
        /// </summary>
        public String GetProd()
        {
            return Encoding.Default.GetString(this.DIC_CONTENT["PROD"]);
        }
    }
}
